home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / doors_1 / gapcdr.zip / CDOOR.ZIP / CDOOR.C next >
C/C++ Source or Header  |  1992-01-12  |  13KB  |  326 lines

  1. /*
  2.     Copyright (C) 1989-1992 The GAP Development Company
  3.  
  4.     All Rights Reserved
  5.  
  6.  
  7.     CDOOR.C
  8.  
  9.     Demonstration program for GAPCDR
  10.  
  11.  
  12.     Microsoft
  13.  
  14.     To compile : cl /c cdoor.c
  15.     To link    : link cdoor,,NUL.MAP,+gapcdrs
  16.  
  17.     ----------------------------------------------------------
  18.  
  19.     Borland
  20.  
  21.     With Borland, YOU have to tell it which of its OWN
  22.     OBJ and LIB files to link in. It isn't smart enough to
  23.     KNOW which ones are required.
  24.  
  25.     Be sure that C0S.OBJ is linked first and that you NAME
  26.     the EXE file (otherwise it will be named C0S.EXE.
  27.  
  28.     To compile : bcc -ms -O -Z -d -c cdoor.c
  29.     To link    : tlink c0s+cdoor,cdoor.exe,NUL.MAP,+gapcdrbs+cs
  30.  
  31.  
  32.     Program will need access to CDOOR.CNF and DOOR.SYS
  33.  
  34. /*
  35.  
  36.  
  37. #define LINT_ARGS
  38.  
  39. #pragma check_stack(off)                  // we dont need stack checking
  40.                                           // IMPORTANT !!
  41. #pragma pack(1)                           // All structures must be packed
  42.                                           // IMPORTANT !!
  43.  
  44.  
  45.    /***********************************************************************/
  46.    /*  Before doing ANYTHING else, include the following files.           */
  47.    /***********************************************************************/
  48.  
  49. #include <stdio.h>                        // C standard header file
  50. #include <dos.h>
  51. #include <stdlib.h>
  52. #include <string.h>
  53.  
  54. #include "compiler.h"                     // defines compiler being used
  55. #include "gapcdr.h"                       // header file for GAPCDR
  56.  
  57.  
  58.    /***********************************************************************/
  59.    /*  Declare any global variables                                       */
  60.    /***********************************************************************/
  61.  
  62.    char anystring1 [250];                 // global garbage collector
  63.  
  64.    // We are placing our Menu inside the program.
  65.    // It can just as easily be a file that we would display.
  66.    // Notice that the Menu contains embedded ANSI codes.
  67.    // Also notice that we don't have a non-color version of the Menu.
  68.    // This is because if the caller is in mono mode, GAPCDR will filter
  69.    // the ANSI codes. It is important to realize that if you have ONLY
  70.    // a color version of a Menu or Display file, that the Menu contain
  71.    // ONLY ANSI color sequences. It cannot contain any other ANSI 
  72.    // sequences such as cursor movement commands. Notice that our
  73.    // Menu uses actual 'spaces' and no cursor sequences. If the Menu
  74.    // contained cursor movement commands and the caller is in non-color
  75.    // mode, the ANSI driver will remove the ANSI sequences (which includes
  76.    // the cursor movement commands) and the screen will not display
  77.    // correctly.
  78.  
  79.    char *menug [] =
  80.       {
  81.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  82.       "          ▒▒▒▒▒▒▒▒┌──────────────────────────────────────┐▒▒▒▒▒▒▒▒▒▒",
  83.       "          ▒▒▒▒▒▒▒▒│              Main Menu               │▒▒▒▒▒▒▒▒▒▒",
  84.       "          ▒▒▒▒▒▒▒▒└──────────────────────────────────────┘▒▒▒▒▒▒▒▒▒▒",
  85.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  86.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  87.       "          ▒▒▒▒▒▒▒▒┌──────────────────────────────────────┐▒▒▒▒▒▒▒▒▒▒",
  88.       "          ▒▒▒▒▒▒▒▒│  [C]olor               [T]op Scores  ▒▒▒▒▒▒▒▒▒▒",
  89.       "          ▒▒▒▒▒▒▒▒│  [D]os Window          [S]how File   ▒▒▒▒▒▒▒▒▒▒",
  90.       "          ▒▒▒▒▒▒▒▒│  [P]age Sysop          [Q]uit        ▒▒▒▒▒▒▒▒▒▒",
  91.       "          ▒▒▒▒▒▒▒▒└──────────────────────────────────────┘▒▒▒▒▒▒▒▒▒▒",
  92.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  93.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  94.       "\0"
  95.       };
  96.  
  97.  
  98.    // declare functions
  99.  
  100.    static void _pascal _near dos_window(short how);
  101.  
  102.  
  103.  
  104.    /***********************************************************************/
  105.    /*  Begin main line code here                                          */
  106.    /***********************************************************************/
  107.  
  108. short main(void)
  109. {
  110.    short oldbell;                         // status of page bell flag
  111.    char **menu;                           // pointer to menu arrays
  112.    char response [80];                    // for getting responses
  113.    char prompt   [80];                    // for the prompt line
  114.  
  115.    FILE *doorcnf;                         // file pointer for cnf file
  116.  
  117.    // remember screen attributes for the DOS Window
  118.  
  119.    get_attr();                            // remember screen attribs
  120.  
  121.  
  122.    /***********************************************************************/
  123.    /*  Before doing ANYTHING else, initialize the door with the following */
  124.    /*  two function calls.                                                */
  125.    /*  Then, if you have any configuration options, read them in and then */
  126.    /*  close the file.                                                    */
  127.    /*  Note that we are hardcoding the name of the configuration file.    */
  128.    /*  Normally, this is passed as a command line parameter so you would  */
  129.    /*  call read_cnf like this :  doorcnf = read_cnf(argv[1]);            */
  130.    /***********************************************************************/
  131.  
  132.    doorcnf = read_cnf("CDOOR.CNF");       // read door configuration file
  133.    init_door();                           // initialize the door
  134.  
  135.    fclose(doorcnf);                       // we dont have any configuration
  136.                                           // options so we will just close
  137.  
  138.  
  139.    /***********************************************************************/
  140.    /*  Lets now build some menus all at once.                             */
  141.    /*  These menus were created with an ANSI editor.  This is perhaps the */
  142.    /*  fastest and easiest way to create menus.                           */
  143.    /***********************************************************************/
  144.  
  145.    do
  146.       {
  147.       // Format the prompt
  148.  
  149.       time_left();                        // get # of mins left
  150.  
  151.       sprintf(prompt,"\r\n%s[%s%d mins%s] Main Command : ",A_YELLOW,
  152.               A_BRED,timeleft,A_YELLOW);
  153.  
  154.       clear_scrn();                       // first clear the screen
  155.  
  156.       nl(2);                              // do a couple of blank lines
  157.  
  158.       menu = menug;                       // set pointer to our menu
  159.  
  160.       while (**menu)                      // now show the menu
  161.          show_mess(*menu++,NO,YES);
  162.  
  163.       show_mess(prompt,NO,NO);            // show the prompt
  164.  
  165.       empty(response,1);                  // initialize response
  166.       get_string(response);               // get user input
  167.  
  168.       switch (response[0])
  169.          {
  170.          case 'C' :                       // toggle color
  171.             if (color)                    // if in color already
  172.                color = 0;                 // turn color flag off
  173.             else                          // otherwise
  174.                color = 1;                 // turn it on
  175.  
  176.             fix_color();                  // tell ANSI driver what we did
  177.             break;
  178.  
  179.          case 'D' :                       // DOS Window
  180.             // show message on local screen so they know how to get
  181.             // back to program
  182.  
  183.             nl(1);
  184.             lputs(A_BWHITE);
  185.             lputs("                      Type 'Exit' to return to program");
  186.  
  187.             dos_window(0);                // make a DOS window
  188.             system("COMMAND");            // shell to DOS
  189.             dos_window(1);                // remove the DOS window
  190.             break;
  191.  
  192.          case 'P' :                       // page the sysop
  193.             oldbell = bell;               // remember original setting
  194.             bell = 1;                     // turn page bell on
  195.             pagesysop();                  // go page the sysop
  196.             bell = oldbell;               // restore setting
  197.             break;
  198.  
  199.          case 'T' :                       // show the scoreboard
  200.             read_score("CDOOR.DAT","Top 10 Players Of Our Example Door");
  201.             
  202.             // add name to score board file
  203.  
  204.             strcpy(response,username);    // remember user name
  205.  
  206.             ansi(A_YELLOW);               // set a color
  207.  
  208.             show_mess("Please Enter Your Name : ", NO,NO);
  209.  
  210.             empty(username,30);           // initialize string
  211.             get_string(username);         // go get a name
  212.  
  213.             if (username[0] != 0)         // if name was entered
  214.                {
  215.                write_score("CDOOR.DAT",20220L);   // write the score
  216.  
  217.                ansi(A_BWHITE);            // set a color
  218.                nl(1);
  219.                show_mess("You are now a Top 10 Player!",NO,YES);
  220.                nl(1);
  221.                pause();
  222.                read_score("CDOOR.DAT","Top 10 Players Of Our Example Door");
  223.                }
  224.  
  225.             strcpy(username,response);    // restore name
  226.  
  227.             break;
  228.  
  229.          case 'S' :                       // show file
  230.             show_file("WELCOME");         // pass base part of filename
  231.             pause();                      // make sure they've seen it
  232.             break;
  233.  
  234.          case 'Q' :                       // quit
  235.             break;
  236.          }
  237.       }
  238.    while (response[0] != 'Q');
  239.  
  240.    leave(0);                              // must exit properly!
  241. }
  242.  
  243.    // makes or removes a DOS Window
  244.    // 0 = make window
  245.    // 1 = remove window
  246.  
  247.    // Our DOS window is 14 rows by 64 columns (including border) - 1792 bytes
  248.  
  249.    // NOTE: The program can NOT, under any circumstance, exit or abort 
  250.    // while the DOS window is being displayed. If it does, the computer
  251.    // will crash. This means that while the window is up, there can be
  252.    // NO input or output using GAPCDR since if carrier is dropped, GAPCDR
  253.    // will shut down, and the BIOS trap will still be operating. The end
  254.    // result is a locked up computer the next time a program is run
  255.  
  256.  
  257.    static unsigned short near dseg = 0;   // DOS stores segment address here
  258.  
  259.    static char near border [] =
  260.       {
  261.       "──────────────────────────────────────────────────────────────"
  262.       };
  263.  
  264.  
  265. static void _pascal _near dos_window(short how)
  266. {
  267.    short r;
  268.  
  269.    if (!how)                              // set up the screen
  270.       {
  271.       // # of bytes to allocate is 
  272.       // (((cols * 2) * rows) / 16) + 2 (for good measure)
  273.  
  274. #ifdef TC
  275.       if (allocmem(114,&dseg) != -1)      // get memory to hold screen
  276. #else
  277.       if (_dos_allocmem(114,&dseg) != 0)  // get memory to hold screen
  278. #endif
  279.          {                                // can't
  280.          dseg = 0;                        // NULL out pointer
  281.          return;                          // return now
  282.          }
  283.  
  284.       lputs("s");                       // remember cursor position for ANSI
  285.       save_screen(3,8,16,71,dseg);        // save underlying window
  286.       normal = 15;                        // Bright White border
  287.  
  288.       crscur = 0x0308;                    // cursor to row 3, column 8
  289.       sprintf(anystring1,"┌%s┐",border);
  290.       lputs(anystring1);                  // show top border
  291.  
  292.       for (r = 4; r < 17; r++)            // display sides of window
  293.          {
  294.          crscur = 0x0008 + (256 * r);     // next line
  295.          lputc('│');                      // left side
  296.          crscur += 62;                    // position cursor
  297.          lputc('│');                      // right side
  298.          }
  299.  
  300.       crscur = 0x1008;                    // cursor to row 16, column 8
  301.       sprintf(anystring1,"└%s┘",border);
  302.       lputs(anystring1);                  // show top border
  303.  
  304.       // set up the BIOS trap so that the cursor stays inside of the
  305.       // window
  306.  
  307.       set_int10();                        // set up BIOS handler
  308.       set_cord(4,9,15,70);                // set window co-ordinates (inside dimensions)
  309.       set_attr(14,1);                     // set window attributes (yellow on blue)
  310.       cls_all();                          // clear the window
  311.       }
  312.    else if (how && dseg != 0)             // remove the screen
  313.       {
  314.       rest_int10();                       // reset BIOS handler
  315.  
  316.       restore_screen(3,8,16,71,dseg);     // restore underlying window
  317. #ifdef TC
  318.       freemem(dseg);                      // free memory
  319. #else
  320.       _dos_freemem(dseg);                 // free memory
  321. #endif
  322.       dseg = 0;                           // NULL out pointer
  323.       lputs("u");                       // restore cursor
  324.       }
  325. }
  326.